import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import getpass
#自动登录
name = "15150678100@163.com"
# passwd = getpass.getpass("输入用户密码：")
passwd = "Ma163611"
url = 'https://music.163.com/'
browser = webdriver.Firefox()
browser.get(url)
time.sleep(5)  # 等待5秒，待界面完全加载
element = browser.find_element_by_xpath("//a[@data-action='login']")
ActionChains(browser).move_to_element(element).click().perform() #点击登录
time.sleep(2)
s = browser.find_element_by_xpath("//input[@id='j-official-terms']")
ActionChains(browser).move_to_element(s).click().perform()  #点击同意
s1 = browser.find_element_by_xpath("//div[@class='zcnt']//a[@data-type='netease']")
ActionChains(browser).move_to_element(s1).click().perform() #网易邮箱方式
time.sleep(3)
browser.find_element_by_name('e').clear()
browser.find_element_by_name('e').send_keys(name) # 输入用户账户
browser.find_element_by_name('epw').clear()
browser.find_element_by_name('epw').send_keys(passwd) # 输入用户密码
browser.find_element_by_xpath('//div/a[@class="js-primary u-btn2 u-btn2-2"]').click() # 点击登录
time.sleep(3)
my_music = browser.find_element_by_xpath("//a[@data-action='bilog']") #我的歌单
ActionChains(browser).move_to_element(my_music).click().perform()
time.sleep(3)
music_id = browser.find_elements_by_xpath("//div[@class='j-flag']//span[@class='txt']/a/@href")
print(music_id)